package cz.zapletalovi.tests;

import com.zapletalovi.tests.ExampleTimer;

import javax.ejb.EJB;
import javax.ejb.EJBAccessException;
import javax.naming.Context;
import javax.naming.InitialContext;
import java.util.Properties;

public class ExampleTimerClient {

    public static void main(String[] args) throws Exception {
        Properties env = new Properties();
        env.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
        env.setProperty(Context.PROVIDER_URL, "jnp://localhost:1099");
        InitialContext ctx = new InitialContext(env);
        ExampleTimer timer = (ExampleTimer) ctx.lookup("ExampleTimerBean/remote");

        try {
            System.out.println("Starting timer bean...");
            timer.scheduleTimer(10000); // 10 sekund
            System.out.println("Started...");
        }
        catch (EJBAccessException ex) {
            System.out.println("Saw expected SecurityException: " + ex.getMessage());
        }
    }
}